﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Entity;
using BAL;
using Common;
using System.Text;
namespace Web
{
    public partial class ChartScoreMain : System.Web.UI.Page
    {
        protected int examroomid = 0, studentid = 0;
        protected string ExamRoomId = "", ExamRoomDate = "";
        protected string AreaName = "", SchoolName = "", GradeName = "", ClassName = "";
        protected string StudentName = "", StudentSex = "", StudentNumber = "";
        protected bool isquery = false;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!UserValidate.CheckLogin(this.Request, "StatistScore"))
            {
                if (!UserValidate.CheckQuery())
                {
                    Response.Write("<script type=\"text/javascript\">top.location.href='login.aspx';</script>");
                    Response.Redirect("login.aspx");
                    Response.End();
                }
                else
                {
                    isquery = true;
                }
            }
            if (isquery)
            {
                studentid = int.Parse(HttpContext.Current.Session["QueryStudentId"] as string);
            }
            else if (!PageValidate.QueryStringIsEmpty("studentid"))
            {
                try
                {
                    studentid = int.Parse(PageValidate.QueryString("studentid"));
                }
                catch (Exception ex)
                {
                    Response.Write(ex.Message);
                    Response.End();
                }
            }
            if (!PageValidate.QueryStringIsEmpty("examroomid"))
            {
                try
                {
                    examroomid = int.Parse(PageValidate.QueryString("examroomid"));
                }
                catch (Exception ex)
                {
                    Response.Write(ex.Message);
                    Response.End();
                }
            }
            if (!IsPostBack)
            {
                if (examroomid > 0 && studentid > 0)
                {
                    ExamRoomInfo examroominfo = ExamRoom.GetSingleInfo(examroomid);
                    StudentInfo studentInfo = Student.GetSingleInfo(studentid);
                    if (examroominfo != null && studentInfo != null)
                    {
                        ExamRoomId = examroominfo.CreateDate.ToShortDateString() + "-" + examroominfo.Id.ToString();
                        ExamRoomDate = examroominfo.ExamStartDate.Value.ToShortDateString() + "-" + examroominfo.ExamEndDate.Value.ToShortDateString();
                        SchoolName = School.GetSingleInfo(studentInfo.SchoolId).Name;
                        GradeName = Grade.GetSingleInfo(studentInfo.GradeId).Name;
                        AreaName = Area.GetSingleInfo(studentInfo.AreaId).Name;
                        ClassName = TClass.GetSingleInfo(studentInfo.ClassId).Name;
                        StudentName = studentInfo.Name;
                        StudentSex = studentInfo.Sex == 0 ? "女" : "男";
                        StudentNumber = studentInfo.Number;
                    }
                    else
                    {
                        Response.Redirect("AdminExamRoom.aspx");
                    }
                }
                else
                {
                    Response.Redirect("AdminExamRoom.aspx");
                }
            }
        }
    }
}
